package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoDgPackingConvert;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoDgPackingDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoDgPackingService;
import com.cmc.cloud.cmclink.doc.vo.specialcargodgpackingvo.SpecialCargoDgPackingBaseVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargodgpackingvo.SpecialCargoDgPackingPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargodgpackingvo.SpecialCargoDgPackingRespVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargodgpackingvo.SpecialCargoDgPackingUpdateReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 特种货审批dg包装前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批dg包装")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/specialCargoDgPacking")
public class SpecialCargoDgPackingController {

    @Resource
    private SpecialCargoDgPackingService specialCargoDgPackingService;

    @Operation(summary = "创建特种货审批dg包装")
    @PostMapping("/create")
    public CommonResult<Void> createSpecialCargoDgPacking(@Valid @RequestBody SpecialCargoDgPackingBaseVO createReqVO) {
        specialCargoDgPackingService.createSpecialCargoDgPacking(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货审批dg包装")
    @PostMapping("/update")
    public CommonResult<Void> updateSpecialCargoDgPacking(@Valid @RequestBody SpecialCargoDgPackingUpdateReqVO updateReqVO) {
        specialCargoDgPackingService.updateSpecialCargoDgPacking(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批dg包装")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoDgPacking(@PathVariable("id") Long id) {
        specialCargoDgPackingService.deleteSpecialCargoDgPacking(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批dg包装")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<SpecialCargoDgPackingRespVO> getSpecialCargoDgPacking(@PathVariable("id") Long id) {
        SpecialCargoDgPackingDO specialCargoDgPacking = specialCargoDgPackingService.getSpecialCargoDgPacking(id);
        return CommonResult.success(SpecialCargoDgPackingConvert.INSTANCE.convert(specialCargoDgPacking));
    }

    @Operation(summary = "获得特种货审批dg包装列表")
    @GetMapping("/list")
    @Parameter(name = "dgId", description = "DG_ID", required = true)
    public CommonResult<List<SpecialCargoDgPackingRespVO>> getSpecialCargoDgPackingList(@RequestParam("dgId") Long dgId) {
        List<SpecialCargoDgPackingDO> list = specialCargoDgPackingService.getSpecialCargoDgPackingList(dgId);
        return CommonResult.success(SpecialCargoDgPackingConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得特种货审批dg包装分页")
    @PostMapping("/page")
    public CommonResult<PageResult<SpecialCargoDgPackingRespVO>> getSpecialCargoDgPackingPage(@RequestBody @Valid SpecialCargoDgPackingPageReqVO pageVO) {
        PageResult<SpecialCargoDgPackingDO> pageResult = specialCargoDgPackingService.getSpecialCargoDgPackingPage(pageVO);
        List<SpecialCargoDgPackingRespVO> results = SpecialCargoDgPackingConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
